//1. 函数 返回值 类型
function sayHi(): string{
  return '1111111'
}

let res1: string = sayHi()
console.log(res1);
// 2.函数 形参 类型 
function jumpSan(City: string): void{
  console.log(City);
}
//2.1 ts中 实参 必须 和 形参的 类型一致
jumpSan('青岛')
// jumpSan(111)
//2.2 ts中 实参 和 形参 的数量 必须一致
// jumpSan() //报错：实参太少
// jumpSan('青岛','111') //报错 实参太多

// function sum(a?:number,b?:number): void{
//   console.log(a,b);
// }
// sum(0)

// function sum(a: number = 10,b:number=20):number {
//   return a+b
// }
// console.log(sum(100,50));
// console.log(sum(100));
// console.log(sum());
// console.log(sum(undefined,50));

function sum(a: number, b: number, ...c: number[]): number{
  return a + b + c.reduce((prev,item) => {
    return prev+item
  },0)
  
}
console.log(sum(1,2,3,4,5,6));
console.log(sum(1,2));

// function buyGun(gunName: string, count?: number): void{
//   console.log(gunName,count ? count : '无');
  
// }
// function buyGun(gunName: string, count: number=1): void{
//   console.log(gunName,count );
  
// }
function buyGun(gunName: string='222', count: number=1): void{
  console.log(gunName,count );
  
}
// buyGun('1111',2)
buyGun()
